home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!news1!news
- From: tjones@walknet.com
- Subject: Need help!
- X-Nntp-Posting-Host: ind-006-236-227.iquest.net
- Message-ID: <Do858A.Btr@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Internet, Inc.
- X-Newsreader: Forte Free Agent 1.0.82
- Date: Thu, 14 Mar 1996 00:05:03 GMT
-
- /*
- I have just started using C++ and have the problem below. Any
- advice would be appreciated.
-
- Can data structures be passed to classes? In this overly simple
- program below, I can fill a data structure in the desc function
- of the reg class, but I can not decrement
- to the beginning of the structure, so that I can print it out
- within the class function.
-
- Please pardon the mix of C and C++ code.
-
- Please e-mail any suggestions to TJONES@WALKERNET.COM
- */
-
-
- #include <dos.h>
- #include <stdlib.h>
- #include <math.h>
- #include <dir.h>
- #include <stdio.h>
- #include <string.h>
-
-
-
- struct data { char name[50];};
-
- class reg {
- public:
- void init(void);
- void desc(struct data *dptr);
- } reg1;
-
- void reg::init(void)
- {
-
- }
- void reg::desc(struct data *dptr)
- { int y=0,x=0;
-
- for(y=0;y<25;y++)
- {for(x=0;x<y;x++) strcat(dptr->name,"A");
- printf("%s\n",dptr->name);
- dptr++;
- }
-
- /* Here is the problem area*/
-
- for(y=0;y<25;y++) dptr--;
-
- for(y=0;y<25;y++)
- printf("\n%4d %s",y,dptr->name);
-
- }
-
- int main(void)
- {
- struct data rrdata[25]; struct data *rptr;
- memset(rrdata,0,sizeof(struct data)*25);
-
- reg1.init();
-
- rptr=&rrdata[0];
- reg1.desc(rptr);
-
- for(int x=0;x<25;x++)
- printf("\n%4d %s",x,rrdata[x].name);
-
- return 0;
- }
-
-
-